package artibella.media.controls.views 
{
	import artibella.IDisposable;
	import artibella.media.AListItem;
	import artibella.text.CrawlingLabel;
	import artibella.ui.scrolls.ScrollingDevice;
	import artibella.ui.scrolls.ScrollingDeviceParameters;
	import artibella.utils.StringsUtils;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author pbordachar
	 */
	
	public class RTB_PlayList extends Sprite implements IDisposable
	{
		private var _tab:Array;
		private var _list:Sprite;
		private var _clr:int;
		private var _scrollingDevice:ScrollingDevice;
		
		public function RTB_PlayList( a:Array, c:int = 0x000000 ) 
		{
			_tab = a;
			_clr = c;
			
			_init();
		}
		
		private function _init():void
		{
			// list
			
			_list = new Sprite();
			var item:CrawlingLabel;
			for ( var i:int = 0; i < _tab.length; i ++ ) 
			{
				item = new CrawlingLabel( 215 );
				item.text = StringsUtils.base10( i + 1 ) + ". " + ( _tab[ i ] as AListItem ).label;
				item.indice = i;
				item.buttonMode = true;
				item.mouseChildren = false;
				item.x = 0;
				item.y = item.height / 2 + ( i * item.height );
				_list.addChild( item );
			}
			
			_list.addEventListener( MouseEvent.CLICK, _doClick );
			
			// scrolling device
			
			var params:ScrollingDeviceParameters = new ScrollingDeviceParameters();
			params.color = 0x666666; // _clr;
			params.hasArrows = false;
			params.scrollPosition = ScrollingDeviceParameters.RIGHT;
			
			_scrollingDevice = new ScrollingDevice( 215, 80, params );
			_scrollingDevice.x = 0;
			_scrollingDevice.y = 0;
			_scrollingDevice.setBoxContent( _list );
			
			addChild( _scrollingDevice );
			
			// separator
			
			var s:Sprite = new Sprite();
			s.graphics.lineStyle( 1, _clr, .3, true );
			s.graphics.lineTo( 226, 0 );
			s.x = 2;
			s.y = 90;
			addChild( s );
		}
		
		private function _doClick( e:MouseEvent ):void
		{
			//trace( e.target.indice );
		}
		
		public function dispose():void
		{
			_list.removeEventListener( MouseEvent.CLICK, _doClick );
			
			_scrollingDevice.dispose();
			_scrollingDevice = null;
		}
		
	}

}